package com.lz.commonlibrary.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * vatty *
 * <p/>
 * hongshengpeng.com
 */
public class QuestionFragmentPagerAdapter extends FragmentStatePagerAdapter {
    private List<Fragment> fragmentsList;

//    private String Title[] = new String[]{"基本检查情况", "现场检查情况", "废水检查情况", "废气检查情况", "危险废物检查情况"};
    private String titleArr[] = null;
    public QuestionFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public QuestionFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragmentsList = fragments;
    }

    public QuestionFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments, String[] titleArr) {
        super(fm);
        this.fragmentsList = fragments;
        this.titleArr = titleArr;
    }

    @Override
    public int getCount() {
        return fragmentsList == null ? 0 :fragmentsList.size();
    }

    @Override
    public Fragment getItem(int arg0) {
        return fragmentsList.get(arg0);
    }


    @Override
    public CharSequence getPageTitle(int position) {
        // TODO Auto-generated method stub
        return  (titleArr == null ||   position >= titleArr.length)? "" : titleArr[position];
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        if(object != null){
            return ((Fragment)object).getView() == view;
        }else{
            return false;
        }
    }




}
